package com.ruoyi.construction.service.impl;

import java.util.Date;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.modules.domain.AuditFlowLog;
import com.ruoyi.modules.mapper.AuditFlowLogMapper;
import com.ruoyi.violation.vo.LawAuditVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.construction.mapper.ConstructionSiteMapper;
import com.ruoyi.construction.domain.ConstructionSite;
import com.ruoyi.construction.service.IConstructionSiteService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 项目工地信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-12-14
 */
@Service
public class ConstructionSiteServiceImpl implements IConstructionSiteService 
{
    @Autowired
    private ConstructionSiteMapper constructionSiteMapper;

    @Autowired
    private AuditFlowLogMapper auditFlowLogMapper;

    /**
     * 查询项目工地信息
     * 
     * @param id 项目工地信息主键
     * @return 项目工地信息
     */
    @Override
    public ConstructionSite selectConstructionSiteById(String id)
    {
        return constructionSiteMapper.selectConstructionSiteById(id);
    }

    /**
     * 查询项目工地信息列表
     * 
     * @param constructionSite 项目工地信息
     * @return 项目工地信息
     */
    @Override
    public List<ConstructionSite> selectConstructionSiteList(ConstructionSite constructionSite)
    {
        return constructionSiteMapper.selectConstructionSiteList(constructionSite);
    }

    /**
     * 新增项目工地信息
     * 
     * @param constructionSite 项目工地信息
     * @return 结果
     */
    @Override
    public int insertConstructionSite(ConstructionSite constructionSite)
    {
        constructionSite.setCreateTime(DateUtils.getNowDate());
        return constructionSiteMapper.insertConstructionSite(constructionSite);
    }

    /**
     * 修改项目工地信息
     * 
     * @param constructionSite 项目工地信息
     * @return 结果
     */
    @Override
    public int updateConstructionSite(ConstructionSite constructionSite)
    {
        constructionSite.setUpdateTime(DateUtils.getNowDate());
        return constructionSiteMapper.updateConstructionSite(constructionSite);
    }

    /**
     * 批量删除项目工地信息
     * 
     * @param ids 需要删除的项目工地信息主键
     * @return 结果
     */
    @Override
    public int deleteConstructionSiteByIds(String[] ids)
    {
        return constructionSiteMapper.deleteConstructionSiteByIds(ids);
    }

    /**
     * 删除项目工地信息信息
     * 
     * @param id 项目工地信息主键
     * @return 结果
     */
    @Override
    public int deleteConstructionSiteById(String id)
    {
        return constructionSiteMapper.deleteConstructionSiteById(id);
    }

    /**
     * 审核
     * @param lawAuditVo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int audit(LawAuditVo lawAuditVo) {
        ConstructionSite constructionSite = constructionSiteMapper.selectConstructionSiteById(lawAuditVo.getId() + "");
        constructionSite.setAuditFlowStatus(5l);
        constructionSite.setUpdateTime(new Date());
        int i = constructionSiteMapper.updateConstructionSite(constructionSite);
        if(i>0){
            AuditFlowLog auditFlowLog = new AuditFlowLog();
            auditFlowLog.setAuditUserId(lawAuditVo.getAuditUserId());
            auditFlowLog.setAuditStatus(lawAuditVo.getAuditStatus());
            auditFlowLog.setAuditReason(lawAuditVo.getReason());
            auditFlowLog.setAuditType(0l);
            auditFlowLog.setCreateTime(new Date());
            auditFlowLog.setStatus(0l);
            auditFlowLog.setViolationReportId(Long.parseLong(constructionSite.getId()));
            i = auditFlowLogMapper.insertAuditFlowLog(auditFlowLog);
        }
        return i;
    }
}
